﻿using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity.Infrastructure;
using BugTracker.Helper;
using BugTracker.Models;
using System.Data;

namespace BugTracker.Controllers
{ 
    public class RoleController : Controller
    {
         Bug_db rl = new Bug_db();
         Session asc_rlsession = new Session();

        //
        // GET: /Role/

        public ViewResult Index()
        {
            //if(asc_rlsession.Session_Info() != null)
            //{
            //    if(asc_rlsession.Session_Auth(asc_rlsession.Session_Info
            
            return View(rl.Roles.ToList());
        }

        //
        // GET: /Role/Details/5

        public ViewResult Details(int id)
        {
            Role role = rl.Roles.Find(id);
            return View(role);
        }

        //
        // GET: /Role/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Role/Create

        [HttpPost]
        public ActionResult Create(Role role)
        {
            if (ModelState.IsValid)
            {
                rl.Roles.Add(role);
                rl.SaveChanges();
                return RedirectToAction("Index");  
            }

            return View(role);
        }
        
        //
        // GET: /Role/Edit/5
 
        public ActionResult Edit(int id)
        {
            Role role = rl.Roles.Find(id);
            return View(role);
        }

        //
        // POST: /Role/Edit/5

        [HttpPost]
        public ActionResult Edit(Role role)
        {
            if (ModelState.IsValid)
            {
                rl.Entry(role).State = EntityState.Modified;
                rl.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(role);
        }

        //
        // GET: /Role/Delete/5
 
        public ActionResult Delete(int id)
        {
            Role role = rl.Roles.Find(id);
            return View(role);
        }

        //
        // POST: /Role/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Role role = rl.Roles.Find(id);
            rl.Roles.Remove(role);
            rl.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            rl.Dispose();
            base.Dispose(disposing);
        }
    }
}